<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="车次id" prop="transportTripsId">
      <el-input v-model="dataForm.transportTripsId" placeholder="车次id"></el-input>
    </el-form-item>
    <el-form-item label="起始机构id" prop="startAgencyId">
      <el-input v-model="dataForm.startAgencyId" placeholder="起始机构id"></el-input>
    </el-form-item>
    <el-form-item label="目的机构id" prop="endAgencyId">
      <el-input v-model="dataForm.endAgencyId" placeholder="目的机构id"></el-input>
    </el-form-item>
    <el-form-item label="任务状态，1为待执行（对应 未发车）、2为进行中（对应在途）、3为待确认（保留状态）、4为已完成（对应 已交付）、5为已取消" prop="status">
      <el-input v-model="dataForm.status" placeholder="任务状态，1为待执行（对应 未发车）、2为进行中（对应在途）、3为待确认（保留状态）、4为已完成（对应 已交付）、5为已取消"></el-input>
    </el-form-item>
    <el-form-item label="任务分配状态(1未分配2已分配3待人工分配)" prop="assignedStatus">
      <el-input v-model="dataForm.assignedStatus" placeholder="任务分配状态(1未分配2已分配3待人工分配)"></el-input>
    </el-form-item>
    <el-form-item label="满载状态(1.半载2.满载3.空载)" prop="loadingStatus">
      <el-input v-model="dataForm.loadingStatus" placeholder="满载状态(1.半载2.满载3.空载)"></el-input>
    </el-form-item>
    <el-form-item label="车辆id" prop="truckId">
      <el-input v-model="dataForm.truckId" placeholder="车辆id"></el-input>
    </el-form-item>
    <el-form-item label="提货凭证" prop="cargoPickUpPicture">
      <el-input v-model="dataForm.cargoPickUpPicture" placeholder="提货凭证"></el-input>
    </el-form-item>
    <el-form-item label="货物照片" prop="cargoPicture">
      <el-input v-model="dataForm.cargoPicture" placeholder="货物照片"></el-input>
    </el-form-item>
    <el-form-item label="运回单凭证" prop="transportCertificate">
      <el-input v-model="dataForm.transportCertificate" placeholder="运回单凭证"></el-input>
    </el-form-item>
    <el-form-item label="交付货物照片" prop="deliverPicture">
      <el-input v-model="dataForm.deliverPicture" placeholder="交付货物照片"></el-input>
    </el-form-item>
    <el-form-item label="提货纬度值" prop="deliveryLatitude">
      <el-input v-model="dataForm.deliveryLatitude" placeholder="提货纬度值"></el-input>
    </el-form-item>
    <el-form-item label="提货经度值" prop="deliveryLongitude">
      <el-input v-model="dataForm.deliveryLongitude" placeholder="提货经度值"></el-input>
    </el-form-item>
    <el-form-item label="交付纬度值" prop="deliverLatitude">
      <el-input v-model="dataForm.deliverLatitude" placeholder="交付纬度值"></el-input>
    </el-form-item>
    <el-form-item label="交付经度值" prop="deliverLongitude">
      <el-input v-model="dataForm.deliverLongitude" placeholder="交付经度值"></el-input>
    </el-form-item>
    <el-form-item label="计划发车时间" prop="planDepartureTime">
      <el-input v-model="dataForm.planDepartureTime" placeholder="计划发车时间"></el-input>
    </el-form-item>
    <el-form-item label="实际发车时间" prop="actualDepartureTime">
      <el-input v-model="dataForm.actualDepartureTime" placeholder="实际发车时间"></el-input>
    </el-form-item>
    <el-form-item label="计划到达时间" prop="planArrivalTime">
      <el-input v-model="dataForm.planArrivalTime" placeholder="计划到达时间"></el-input>
    </el-form-item>
    <el-form-item label="实际到达时间" prop="actualArrivalTime">
      <el-input v-model="dataForm.actualArrivalTime" placeholder="实际到达时间"></el-input>
    </el-form-item>
    <el-form-item label="计划提货时间" prop="planPickUpGoodsTime">
      <el-input v-model="dataForm.planPickUpGoodsTime" placeholder="计划提货时间"></el-input>
    </el-form-item>
    <el-form-item label="实际提货时间" prop="actualPickUpGoodsTime">
      <el-input v-model="dataForm.actualPickUpGoodsTime" placeholder="实际提货时间"></el-input>
    </el-form-item>
    <el-form-item label="计划交付时间" prop="planDeliveryTime">
      <el-input v-model="dataForm.planDeliveryTime" placeholder="计划交付时间"></el-input>
    </el-form-item>
    <el-form-item label="实际交付时间" prop="actualDeliveryTime">
      <el-input v-model="dataForm.actualDeliveryTime" placeholder="实际交付时间"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          transportTripsId: '',
          startAgencyId: '',
          endAgencyId: '',
          status: '',
          assignedStatus: '',
          loadingStatus: '',
          truckId: '',
          cargoPickUpPicture: '',
          cargoPicture: '',
          transportCertificate: '',
          deliverPicture: '',
          deliveryLatitude: '',
          deliveryLongitude: '',
          deliverLatitude: '',
          deliverLongitude: '',
          planDepartureTime: '',
          actualDepartureTime: '',
          planArrivalTime: '',
          actualArrivalTime: '',
          planPickUpGoodsTime: '',
          actualPickUpGoodsTime: '',
          planDeliveryTime: '',
          actualDeliveryTime: '',
          createTime: ''
        },
        dataRule: {
          transportTripsId: [
            { required: true, message: '车次id不能为空', trigger: 'blur' }
          ],
          startAgencyId: [
            { required: true, message: '起始机构id不能为空', trigger: 'blur' }
          ],
          endAgencyId: [
            { required: true, message: '目的机构id不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '任务状态，1为待执行（对应 未发车）、2为进行中（对应在途）、3为待确认（保留状态）、4为已完成（对应 已交付）、5为已取消不能为空', trigger: 'blur' }
          ],
          assignedStatus: [
            { required: true, message: '任务分配状态(1未分配2已分配3待人工分配)不能为空', trigger: 'blur' }
          ],
          loadingStatus: [
            { required: true, message: '满载状态(1.半载2.满载3.空载)不能为空', trigger: 'blur' }
          ],
          truckId: [
            { required: true, message: '车辆id不能为空', trigger: 'blur' }
          ],
          cargoPickUpPicture: [
            { required: true, message: '提货凭证不能为空', trigger: 'blur' }
          ],
          cargoPicture: [
            { required: true, message: '货物照片不能为空', trigger: 'blur' }
          ],
          transportCertificate: [
            { required: true, message: '运回单凭证不能为空', trigger: 'blur' }
          ],
          deliverPicture: [
            { required: true, message: '交付货物照片不能为空', trigger: 'blur' }
          ],
          deliveryLatitude: [
            { required: true, message: '提货纬度值不能为空', trigger: 'blur' }
          ],
          deliveryLongitude: [
            { required: true, message: '提货经度值不能为空', trigger: 'blur' }
          ],
          deliverLatitude: [
            { required: true, message: '交付纬度值不能为空', trigger: 'blur' }
          ],
          deliverLongitude: [
            { required: true, message: '交付经度值不能为空', trigger: 'blur' }
          ],
          planDepartureTime: [
            { required: true, message: '计划发车时间不能为空', trigger: 'blur' }
          ],
          actualDepartureTime: [
            { required: true, message: '实际发车时间不能为空', trigger: 'blur' }
          ],
          planArrivalTime: [
            { required: true, message: '计划到达时间不能为空', trigger: 'blur' }
          ],
          actualArrivalTime: [
            { required: true, message: '实际到达时间不能为空', trigger: 'blur' }
          ],
          planPickUpGoodsTime: [
            { required: true, message: '计划提货时间不能为空', trigger: 'blur' }
          ],
          actualPickUpGoodsTime: [
            { required: true, message: '实际提货时间不能为空', trigger: 'blur' }
          ],
          planDeliveryTime: [
            { required: true, message: '计划交付时间不能为空', trigger: 'blur' }
          ],
          actualDeliveryTime: [
            { required: true, message: '实际交付时间不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/aggregation/tasktransport/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.transportTripsId = data.taskTransport.transportTripsId
                this.dataForm.startAgencyId = data.taskTransport.startAgencyId
                this.dataForm.endAgencyId = data.taskTransport.endAgencyId
                this.dataForm.status = data.taskTransport.status
                this.dataForm.assignedStatus = data.taskTransport.assignedStatus
                this.dataForm.loadingStatus = data.taskTransport.loadingStatus
                this.dataForm.truckId = data.taskTransport.truckId
                this.dataForm.cargoPickUpPicture = data.taskTransport.cargoPickUpPicture
                this.dataForm.cargoPicture = data.taskTransport.cargoPicture
                this.dataForm.transportCertificate = data.taskTransport.transportCertificate
                this.dataForm.deliverPicture = data.taskTransport.deliverPicture
                this.dataForm.deliveryLatitude = data.taskTransport.deliveryLatitude
                this.dataForm.deliveryLongitude = data.taskTransport.deliveryLongitude
                this.dataForm.deliverLatitude = data.taskTransport.deliverLatitude
                this.dataForm.deliverLongitude = data.taskTransport.deliverLongitude
                this.dataForm.planDepartureTime = data.taskTransport.planDepartureTime
                this.dataForm.actualDepartureTime = data.taskTransport.actualDepartureTime
                this.dataForm.planArrivalTime = data.taskTransport.planArrivalTime
                this.dataForm.actualArrivalTime = data.taskTransport.actualArrivalTime
                this.dataForm.planPickUpGoodsTime = data.taskTransport.planPickUpGoodsTime
                this.dataForm.actualPickUpGoodsTime = data.taskTransport.actualPickUpGoodsTime
                this.dataForm.planDeliveryTime = data.taskTransport.planDeliveryTime
                this.dataForm.actualDeliveryTime = data.taskTransport.actualDeliveryTime
                this.dataForm.createTime = data.taskTransport.createTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/aggregation/tasktransport/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'transportTripsId': this.dataForm.transportTripsId,
                'startAgencyId': this.dataForm.startAgencyId,
                'endAgencyId': this.dataForm.endAgencyId,
                'status': this.dataForm.status,
                'assignedStatus': this.dataForm.assignedStatus,
                'loadingStatus': this.dataForm.loadingStatus,
                'truckId': this.dataForm.truckId,
                'cargoPickUpPicture': this.dataForm.cargoPickUpPicture,
                'cargoPicture': this.dataForm.cargoPicture,
                'transportCertificate': this.dataForm.transportCertificate,
                'deliverPicture': this.dataForm.deliverPicture,
                'deliveryLatitude': this.dataForm.deliveryLatitude,
                'deliveryLongitude': this.dataForm.deliveryLongitude,
                'deliverLatitude': this.dataForm.deliverLatitude,
                'deliverLongitude': this.dataForm.deliverLongitude,
                'planDepartureTime': this.dataForm.planDepartureTime,
                'actualDepartureTime': this.dataForm.actualDepartureTime,
                'planArrivalTime': this.dataForm.planArrivalTime,
                'actualArrivalTime': this.dataForm.actualArrivalTime,
                'planPickUpGoodsTime': this.dataForm.planPickUpGoodsTime,
                'actualPickUpGoodsTime': this.dataForm.actualPickUpGoodsTime,
                'planDeliveryTime': this.dataForm.planDeliveryTime,
                'actualDeliveryTime': this.dataForm.actualDeliveryTime,
                'createTime': this.dataForm.createTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
